
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>主页</title>
    <style type="text/css">
        td{text-align: center;}
        .td2{text-align: right;}
        .table1{
            border:1px solid #ddd;
            width:900px;
        }
        thead{
            background-color:lightblue;
        }
    </style>
    <script >
        function  togo(){

            var ym=document.getElementById("pageCode").value;

            if(!/^[1-9]\d*$/.test(ym)) {//对当前页码进行整数校验
                alert('请输入正确的页码！');
                return;
            }
            if(ym > ${pagemsg.totalPage}) {//判断当前页码是否大于最大页
                alert('请输入正确的页码！');
                return;
            }
            window.location= "${pageContext.request.contextPath }/main?currentPage="+ym;
        }
    </script>
</head>
<body>
<%
    String name= (String) session.getAttribute("currentUser");
%>
欢迎你：<%=name%>
<br>
<%-- 当前用户：${pageScope.currentUser}<!-- (只能在同一个页面中使用) --> <br>
当前用户：${requestScope.currentUser}-${roleName} 有重定向数据就访问不到<br>
当前用户：${sessionScope.currentUser}-${roleName} 可以使用<br> --%>
<hr>
<a href="add"> 添加用户</a><br>
<a href="examlogin">在线考试</a>
<c:if test="${empty pagemsg}">
    没有任何用户信息！
</c:if>
<c:if test="${!empty pagemsg}">
    <table border="1" cellpadding="10" cellspacing="0" class="table1">
        <thead>
        <tr>
            <td>编号</td>
            <td>用户名</td>
            <td>密码</td>
            <td>邮件</td>
            <td>联系电话</td>
            <td>职位</td>
            <td>Edit</td>
            <td>Delete</td>
        </tr>
        </thead>
        <c:forEach items="${requestScope.pagemsg.lists}" var="u">
            <tr>
                <th>${u.id }</th>
                <th>${u.username }</th>
                <th>${u.password }</th>
                <th>${u.email }</th>
                <th>${u.phone }</th>
                <th>${u.rolename }</th>
                <th><a href="edit?id=${u.id}">Edit</a></th>
                <th><a href="delete?id=${u.id}" onclick="return confirm('确定要删除吗')">Delete</a></th>
            </tr>
        </c:forEach>
    </table>
</c:if>

<table  border="0" cellspacing="0" cellpadding="0"  width="900px">
    <tr>

        <td class="td2">
            <span>第${requestScope.pagemsg.currPage }/ ${requestScope.pagemsg.totalPage}页</span>  
            <span>总记录数：${requestScope.pagemsg.totalCount }  每页显示:${requestScope.pagemsg.pageSize}</span>  
            <span>
       <c:if test="${requestScope.pagemsg.currPage != 1}">
           <a href="${pageContext.request.contextPath }/main?currentPage=1">[首页]</a>  
           <a href="${pageContext.request.contextPath }/main?currentPage=${requestScope.pagemsg.currPage-1}">[上一页]</a>  
       </c:if>
       <c:choose>
       <c:when test="${pagemsg.totalPage <=6}">
                      <c:set var="begin" value="1"/>
                      <c:set var="end" value="${pagemsg.totalPage}"/>
       </c:when>
       <c:otherwise>
           <c:set var="begin" value="${pagemsg.currPage-2}"/>
           <c:set var="end" value="${pagemsg.currPage+3}"/>
           <c:if test="${begin<1}">
               <c:set var="begin" value="1"/>
               <c:set var="end" value="6"/>
           </c:if>
           <c:if test="${end>pagemsg.totalPage}">
               <c:set var="begin" value="${pagemsg.totalPage-5}"/>
               <c:set var="end" value="${pagemsg.totalPage}"/>
           </c:if>
       </c:otherwise>
       </c:choose>
       <c:forEach begin="${begin}" end="${end}" var="i">
           <c:choose>
               <c:when test="${i eq pagemsg.currPage}">
               <span class="spanBtnSelect">${i}</span>
               </c:when>
               <c:otherwise>
                   <a href="${pageContext.request.contextPath }/main?currentPage=${i}" class="aBtn">${i }</a>
               </c:otherwise>
           </c:choose>
       </c:forEach>
       <c:if test="${end < pagemsg.totalPage }">
               <span class="spanApostrophe">...</span>
       </c:if>

        <c:if test="${requestScope.pagemsg.currPage != requestScope.pagemsg.totalPage}">
           <a href="${pageContext.request.contextPath }/main?currentPage=${requestScope.pagemsg.currPage+1}">[下一页]</a>  
           <a href="${pageContext.request.contextPath }/main?currentPage=${requestScope.pagemsg.totalPage}">[尾页]</a>  
       </c:if>


            <span>到</span>
            <input type="text" class="inputPageCode" id="pageCode" value="${pagemsg.currPage}"/>
            <span>页</span>
             <input type="button" value="确定" onclick="togo()">
        </td>

    </tr>
</table>
</body>
</html>